
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
        static int n, m;
        static char[][] map;
        static boolean[][] visit;
        static int[][] f = {{-1, -2},{-2, -1},{-2, 1},{-1, 2},{1, 2},{2, 1},{2, -1},{1, -2}};
        static int ans;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        m = scan.nextInt();
        n = scan.nextInt();
        map = new char[n][m];
        visit = new boolean[n][m];
        String[] grip = new String[n];
            for (int i = 0; i < n ; i ++){
                grip[i] = scan.next();
                char[] temp = grip[i].toCharArray();
                System.out.println(temp.length);
                for (int j = 0; j < m; j ++){
                    map[i][j] = temp[j];
                }
            }

        for (int i = 0; i < n; i ++){
            for (int j = 0; j < m; j ++){
                if (!visit[i][j] && map[i][j] == 'K'){
                    dfs(map, i ,j);
                }
            }
        }
        System.out.println(ans);
    }
    static void dfs(char[][] map, int x, int y){

        if (map[x][y] == 'H') {
            return;
        }
        for (int i = 0; i < 8; i ++){
            int dx = x + f[i][0], dy = y + f[i][1];
            if (dx < 0 || dx >= n || dy < 0 || dy >= m){
                continue;
            }

            if(!visit[dx][dy] && map[dx][dy] != '*'){
                ans ++;
                visit[dx][dy] = true;
                dfs(map, dx, dy);
                visit[dx][dy] = false;
            }
        }
    }
}
